package com.qiaofang.applet.service.property.service.mapstruct;

import com.qiaofang.applet.service.other.service.dto.MainSearchDetailDTO;
import com.qiaofang.applet.service.property.domain.Estate;
import com.qiaofang.applet.service.property.domain.EstateComment;
import com.qiaofang.applet.service.property.domain.Property;
import com.qiaofang.applet.service.property.service.dto.*;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.support.PageableExecutionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: youqing.yang
 * @create: 2020/09/17 16:50
 **/
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface EstateMapper {

    MainSearchDetailDTO domainToDtailDto(Property property);

    EstateListDto domainToListDto(Estate estate);

    EstateDetailDto domainToDetailDto(Estate estate);

    EstateShowDto domainToShowDto(Estate estate);

    List<EstateListDto> domainToListDto(List<Estate> estate);

    default Page<EstateListDto> convertDomainToEstateListDto(Page<Estate> propertyPage) {
        List<EstateListDto> content = new ArrayList<>();

        if (propertyPage.getTotalElements() > 0) {
            content = propertyPage.getContent().stream().map(this::domainToListDto).collect(Collectors.toList());
        }
        return PageableExecutionUtils.getPage(content, propertyPage.getPageable(), () -> propertyPage.getTotalElements());
    }

    List<EstateCommentDto> dtoListToDtoList(List<EstateComment> list);


    List<EstateCommentAdminDto> domainListToDtoList(List<EstateComment> list);



}
